//
//  RunRecordHeader.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/8/26.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "RunRecordHeader.h"
#import "RunRecordGroupInfo.h"
@interface RunRecordHeader()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *month;
@property (weak, nonatomic) IBOutlet UILabel *distance;
@property (weak, nonatomic) IBOutlet UILabel *time;
- (IBAction)clickedExpand:(id)sender;

@end

@implementation RunRecordHeader

+ (instancetype)headerViewWithTableView:(UITableView *)tableView//获取头文件
{
    static NSString *reuseId = @"header";
    RunRecordHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseId];
    if (header == nil){
        header = [[self alloc] initWithReuseIdentifier:reuseId];
    }
    return header;
}

//2 创建子控件 没有初始化frame
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"RunRecordHeader" owner:nil options:nil] lastObject];
        }
    return self;
}
//当xib中的控件加载完成会调用此方法
- (void)awakeFromNib
{
    NSLog(@"awakeFromNib");
}

- (IBAction)clickedExpand:(id)sender{
    NSLog(@"clickedExpand");
    self.data.expend = !self.data.expend;//是否展开
    if ([self.delegate respondsToSelector:@selector(headerViewDidClickedNameView:)]) {
        [self.delegate headerViewDidClickedNameView:self];
    }
}
-(void)setData:(RunRecordGroupInfo *)data{//显示数据
    _data =data;
    _month.text=_data.month;
    NSString *dis =[NSString stringWithFormat:@"%.1f",_data.distance/1000];//总距离
    dis =[dis stringByAppendingString:@"km"];
    NSString *time =[NSString stringWithFormat:@"%.1f",_data.time/3600];
    _distance.text=dis;
    _time.text =time;
}
@end
